//
// Created by 李传智 on 2018/4/12.
//

#include "VideoData.h"

extern "C" {
#include <libavformat/avformat.h>
}

bool VideoData::alloc(int size, const char *data) {
    free();
    if (size <= 0) {
        return false;
    }
    this->data = new unsigned char[size];
    if (!this->data) {
        return false;
    }
    this->size = size;
    this->dataType = DATA_U_CHAR;
    if (data) {
        memcpy(this->data, data, (size_t) size);
    }
    return true;
}

void VideoData::free() {
    if (!data) return;
    if (dataType == DATA_AV_PACKET) {
        av_packet_free((AVPacket **) &data);
    } else {
        delete data;
    }
    data = 0;
    size = 0;
}